home *** CD-ROM | disk | FTP | other *** search
- page ,132
- ;
- ; settime.asm
- ;
- ; The other day as I was entering the time for
- ; PC-DOS 3.1, I asked myself 'Why am I doing
- ; this? The computer ahs a clock built in!'.
- ; This routine reads battery backed clock in the
- ; AT&T 6300 and sets DOS time from it.
- ;
-
- settime segment
- assume cs:settime, ds:settime
- org 100h
-
- start:
- jmp over_data
-
- ;
- ; data area
- ;
- ; putting the data at the beginning of the program
- ; allows the assembler to generate more efficient
- ; code. (I always wondered why everyone did that)
- ;
-
- ; set up string for display
- msg db 'DOS time set to '
- ten_hour db 30h
- unit_hour db 30h
- db ':'
- ten_minute db 30h
- unit_minute db 30h
- db ':'
- ten_second db 30h
- unit_second db 30h
- db '.'
- tenth_second db 30h
- hundreth_second db 30h
- db '$'
-
- ;
- ; code
- ;
-
- over_data:
-
- ;
- ; use AT&T bios to get the time.
- ; registers are set for an immediate call to the dos set time function
- ;
-
- mov ah,-2 ; BIOS 'read clock' flag
- int 1ah ; call BIOS
-
- ;
- ; set dos time
- ;
-
- mov ah,2dh ; DOS 'set time' function
- int 21h ; call DOS
-
- ;
- ; convert values for display
- ;
-
- ; hour
-
- mov al,ch
- call conv_hex
- add ten_hour,al
- add unit_hour,ah
-
- ; minute
-
- mov al,cl
- call conv_hex
- add ten_minute,al
- add unit_minute,ah
-
- ; second
-
- mov al,dh
- call conv_hex
- add ten_second,al
- add unit_second,ah
-
- ; tenth second
-
- mov al,dl
- call conv_hex
- add tenth_second,al
- add hundreth_second,ah
-
- ;
- ; suppress possible leading zero on displayed time
- ;
-
- cmp ten_hour,30h ; is the hour > ten?
- jne display_time ; nope, just display time
- mov ten_hour,20h ; set leading 0 to ' '
-
- ; display the time
-
- display_time:
- mov dx,offset msg ; point to string to print
- mov ah,09h ; DOS 'print string' function
- int 21h ; call DOS
-
- ;
- ; exit to dos
- ;
-
- mov ah,4ch ; DOS 'terminate process' function
- mov al,00h ; return code
- int 21h ; call DOS
-
- ;
- ; convert hex to decimal
- ;
- ; input:
- ; al - hex byte
- ;
- ; output:
- ; ah - decimal units of hex byte
- ; al - decimal tens of hex byte
- ;
- ; trash:
- ; none
- ;
-
- conv_hex:
- push dx ; save dx (seconds values)
- xor ah,ah
- mov dh,0ah ; dh = divisor
- div dh ; ah = remainder = low BCD digit (0-9)
- ; al = quotient = high BCD digit
- pop dx ; restore dx
- ret
-
- settime ends
-
- end start
-